//
//  ONAddSymbolTableViewCell.m
//  Volatix
//
//  Created by Nguyen Minh Duc on 6/5/14.
//  Copyright (c) 2014 Familly. All rights reserved.
//

#import "ONAddSymbolTableViewCell.h"

#define IMAGE_CHECK [UIImage imageNamed:@"ic_checked_color"]
#define IMAGE_UN_CHECK [UIImage imageNamed:@"ic_uncheck"]
#define COLOR_CHECK [UIColor colorWithRed:81.00/255.00 green:180.00/255.00 blue:0 alpha:1]
#define COLOR_UN_CHECK [UIColor blackColor]

#define fontSize 17

@implementation ONAddSymbolTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self) {
        // Initialization code
        
        self = [[[NSBundle mainBundle] loadNibNamed:@"ONAddSymbolTableViewCell" owner:self options:nil] objectAtIndex:0];
        
    }
    return self;
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)loadCellData:(ONISOObjects*)ISOObject{
     self.titleLabel.text = @"";
    self.titleLabel.text = ISOObject.name;
    self.data = ISOObject;
    
    
    if(!ISOObject.hasChild)
    {
        [self.itemClick setHidden:true];
    }
    
    if(ISOObject.isAdded){
        self.isChecked.tag =1;
        [self.isChecked setImage:IMAGE_CHECK forState:UIControlStateNormal];
        self.titleLabel.textColor = COLOR_CHECK;
        self.titleLabel.font = [UIFont boldSystemFontOfSize:fontSize];
    }else{
        self.isChecked.tag =0 ;
        [self.isChecked setImage:IMAGE_UN_CHECK forState:UIControlStateNormal];
        self.titleLabel.textColor = COLOR_UN_CHECK;
        self.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    }
}

- (IBAction)itemDidSelected:(id)sender {
    [self.delegate oNAddSymbolTableViewCelldidSelectObject:self.data];
}

-(void)cellWillSelect:(BOOL)isSelect{
    if(isSelect){
        self.isChecked.tag =1;
        [self.isChecked setImage:IMAGE_CHECK forState:UIControlStateNormal];
        self.titleLabel.textColor = COLOR_CHECK;
        self.titleLabel.font = [UIFont boldSystemFontOfSize:fontSize];
    }else{
        self.isChecked.tag =0 ;
        [self.isChecked setImage:IMAGE_UN_CHECK forState:UIControlStateNormal];
        self.titleLabel.textColor = COLOR_UN_CHECK;
        self.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    }
}

- (IBAction)check:(id)sender {
    [self checkItem:self.isChecked];
}


- (IBAction)checkItem:(id)sender {
    UIButton *btn = (UIButton*)sender;
    if(btn.tag ==0){
        btn.tag =1;
        [btn setImage:IMAGE_CHECK forState:UIControlStateNormal];
        self.titleLabel.textColor = COLOR_CHECK;
        self.titleLabel.font = [UIFont boldSystemFontOfSize:fontSize];
        [self.delegate ONAddSymbolTableViewCellDidselected:self.data];
    }else{
        btn.tag =0 ;
        [btn setImage:IMAGE_UN_CHECK forState:UIControlStateNormal];
        self.titleLabel.textColor = COLOR_UN_CHECK;
        self.titleLabel.font = [UIFont systemFontOfSize:fontSize];
        [self.delegate ONAddSymbolTableViewCellDidRemoved:self.data];
    }
}


@end
